<template>
  <el-card class="box-card">
    <!-- 搜索框 -->
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="商品名称" class="movement">
          <el-input
            v-model="formInline.goods_name"
            placeholder="请输入商品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="时间" class="movement">
          <!-- :picker-options="pickerOptions" -->
          <el-date-picker
            v-model="formInline.time"
            type="datetimerange"
            @change="timeChange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            :clearable="false"
          >
          </el-date-picker>
        </el-form-item>

        <!-- <el-form-item label="时间">
          <el-date-picker
            v-model="formInline.time"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="状态" class="movement">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="手机号" class="movement">
          <el-input
            v-model="formInline.phone_number"
            placeholder="请输入手机号"
            class="movement"
          ></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="search()" class="movement"
            >查询</el-button
          >
          <el-button type="primary" @click="reset()" class="movement"
            >重置</el-button
          >
          <el-button type="primary" @click="handleAdd">新增推广</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 列表展示 -->
    <div>
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%"
        max-height="600"
      >
        <el-table-column label="ID" align="center" width="70" prop="id">
        </el-table-column>
        <el-table-column prop="module_name" align="center" label="推广商品名称">
          <template slot-scope="scope">
            <span>{{ scope.row.good ? scope.row.good.name : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="img"
          align="center"
          label="商品图片"
        >
          <template slot-scope="scope">
            <el-image
              style="width: 50px; height: 50px"
              :src="
                scope.row.good != null
                  ? scope.row.good.img
                    ? imgHeader + scope.row.good.img.split(',')[0]
                    : imgHeader + scope.row.good.images
                  : ''
              "
              fit="cover"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="sort" align="center" label="排序">
        </el-table-column>
        <el-table-column prop="time" align="center" label="推广时间">
        </el-table-column>
        <!-- <el-table-column prop="position_name" align="center" label="职位">
        </el-table-column> -->
        <el-table-column prop="status_en" align="center" label="状态">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status == 1"
              type="warning"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              >结束推广</el-button
            >
            <!-- <el-button
              v-if="scope.row.status == 0"
              type="success"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
              >开始推广</el-button
            > -->
            <el-button
              type="danger"
              size="mini"
              @click="deleteUser(scope.$index, scope.row)"
              >删除</el-button
            >
            <!-- <el-button
              type="primary"
              size="mini"
              @click="compile(scope.$index, scope.row)"
              >查看</el-button
            > -->
            <el-button
              type="primary"
              size="mini"
              @click="compile(scope.$index, scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 100, 200, 300]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 新增员工 -->
    <el-dialog
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose"
    >
      <el-form
        :model="formLabelAlign"
        label-width="120px"
        ref="managementForm"
        :rules="rules"
      >
        <div class="oneLine">
          <!-- <el-form-item label="姓名" prop="name">
            <el-input
              v-model="formLabelAlign.name"
              placeholder="请输入员工姓名"
            ></el-input>
          </el-form-item> -->
          <el-form-item label="模块" class="movement" prop="module">
            <el-select
              :disabled="disabled"
              v-model="formLabelAlign.module"
              @change="moduleSelect1()"
              placeholder="请选择"
            >
              <el-option
                v-for="item in moduleOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="分类" class="movement" prop="class">
            <el-cascader
              :disabled="disabled"
              class="input"
              v-model="formLabelAlign.class"
              :options="classOptions"
              :props="fenleiListProps"
              :show-all-levels="false"
              @change="classChange"
            ></el-cascader>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="选择商品" class="movement" prop="goods">
            <el-select
              :disabled="disabled"
              v-model="formLabelAlign.goods"
              filterable
              placeholder="请选择"
              @change="goodsChange"
            >
              <el-option
                v-for="item in goodsOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="商品品牌">
            <el-input
              :disabled="true"
              v-model="formLabelAlign.brand_name"
              placeholder="请输入商品品牌"
            ></el-input>
          </el-form-item>
        </div>

        <div class="oneLine">
          <el-form-item label="商品图片" prop="imageUrl">
            <div class="unlodBox">
              <el-image
                class="imageGood"
                :src="imageUrl"
                style="width: 360px; height: 180px"
              ></el-image>
              <!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
              <!-- <el-upload
                class="upload-demo"
                action
                :http-request="uploadFiles"
                ref="upload"
                :limit="fileLimit"
                :on-remove="handleRemove"
                :file-list="fileList"
                :on-exceed="handleExceed"
                :before-upload="beforeUpload"
                :show-file-list="false"
                :headers="headers"
              >
                <el-image
                  v-if="imageUrl"
                  class="imageGood"
                  :src="imageUrl"
                  style="width: 360px; height: 180px"
                ></el-image>
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                <div slot="tip" class="el-upload__tip">
                  只能上传jpg/png文件，且不超过5M
                </div>
              </el-upload> -->
            </div>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="是否推广到首页" prop="split_up_num">
            <el-radio-group v-model="formLabelAlign.split_up_num">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="排序" prop="sort">
            <el-input
              v-model="formLabelAlign.sort"
              placeholder="请输入排序"
            ></el-input>
          </el-form-item>
        </div>
        <div class="oneLine">
          <el-form-item label="时间" prop="time">
            <el-date-picker
              v-model="formLabelAlign.time"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              @change="datePicker2"
            >
            </el-date-picker>
          </el-form-item>
        </div>
      </el-form>
      <div>
        <el-button
          type="primary"
          dialogVisible
          class="confirm"
          @click="submitData('managementForm')"
          >确定</el-button
        >
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  user_po_list,
  uploadFiles,
  employee,
  condition,
  userDelete,
  compileAuth,
  goodSort,
  goodsList,
} from "../../../utils/api";
import {
  getPlatformPromotionList,
  getPlatformPromotionDetail,
  addPlatformPromotionList,
  delPlatformPromotionList,
  endPlatformPromotionList,
} from "../../../utils/main";

export default {
  data() {
    return {
      fenleiListProps: {
        label: "name",
        value: "id",
        children: "child",
        emitPath: false,
      },
      materials: "",
      loading: false,
      token: sessionStorage.getItem("token"),
      formInline: {
        goods_name: "",
        status: "",
        time: "",
      },
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      options: [
        {
          value: "3",
          label: "待推广",
        },
        {
          value: "1",
          label: "推广中",
        },
        {
          value: "2",
          label: "已结束",
        },
      ],
      moduleOptions: [
        // 传的时候是4
        {
          value: 1,
          label: "水站",
        },
        // 传的时候是5
        {
          value: 3,
          label: "超市",
        },
        {
          value: 6,
          label: "辅材",
        },
      ],
      classOptions: [],
      goodsOptions: [],
      //新增员工弹框
      disabled: false,
      dialogVisible: false,
      currentPage: 1,
      total: 0,
      limit: 10,
      page: 1,
      authority_id: 5,
      detailData: {},
      tableData: [
        {
          id: "",
          user_id: "",
          name: "",
          phone_number: "",
          identity_img1: "",
          identity_img2: "",
          authority_id: "",
          position_name: "",
          is_status: "",
          names: "",
          img: "",
          image: "",
          is_baiben: "",
          jiguan: "",
          gonling: "",
          user_skill: "",
        },
      ],
      //新增员工
      formLabelAlign: {
        module: "1",
        class: "1",
        goods: "1",
        brand_name: "1",
        split_up_num: "1",
        sort: "1",
        time: "1",
      },
      category_id: "",
      imgHeader: this.Global.imgHeader,
      //上传图片
      imageUrl: "",
      fileList: [],
      fileType: ["png", "jpg", "jpeg"],
      fileLimit: 1,
      headers: { "Content-Type": "multipart/form-data" },
      time1: "",
      startTimes: "",
      endTimes: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now();
        },
      },
      //校验
      rules: {
        module: [
          {
            required: true,
            message: "请选择模块",
            trigger: "change",
          },
        ],
        class: [{ required: true, message: "请选择分类", trigger: "change" }],
        goods: [{ required: true, message: "请选择商品", trigger: "change" }],
        split_up_num: [
          {
            required: true,
            message: "请选择是否推广到首页",
            trigger: "change",
          },
        ],
        sort: [
          { required: true, message: "请输入排序", trigger: "blur" },
          {
            validator: function (rule, value, callback) {
              if (/^\d+$/.test(value) == false) {
                callback(new Error("请输入不小于0的整数"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        time: [
          { required: true, message: "请选择推广时间", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    timeChange() {
      console.log("时间", this.formInline.time);
    },
    //新增员工的数据
    clearData() {
      this.formLabelAlign = {
        module: "",
        class: "",
        goods: "",
        brand_name: "",
        split_up_num: "",
        sort: "",
        time: "",
      };
      (this.classOptions = []), (this.goodsOptions = []), (this.imageUrl = "");
    },
    moduleSelect1() {
      this.formLabelAlign.goods = "";
      if (this.formLabelAlign.module == 6) {
        this.materials = "辅材采购";
        this.fenleiListProps.children = "children";
      } else {
        this.materials = "";
        this.fenleiListProps.children = "child";
      }
      this.moduleSelect(this.formLabelAlign.module, this.materials);
    },
    // 根据商品分类获取商品列表
    getShopList(goods_type_id, goods_cat_id, materials) {
      if (materials == "辅材采购") {
        goods_cat_id = "";
        this.category_id = this.formLabelAlign.class;
      } else {
        goods_cat_id = this.formLabelAlign.class;
        this.category_id = "";
      }
      goodsList(
        this.token,
        1,
        10,
        goods_type_id,
        "",
        "",
        "",
        "",
        "",
        goods_cat_id,
        this.category_id,
        materials
      )
        .then((res) => {
          if (res.data.status) {
            this.goodsOptions = res.data.data.data;
            console.log("o", this.goodsOptions);
            // this.total = res.data.data.count;
            // this.tableData.forEach((item) => {
            //   item.aimages = [];
            //   item.aimages.push("https://bjsf.bjsky.top" + item.images);
            // });
            // let timer = setTimeout(() => {
            //   this.loading = false;
            //   clearTimeout(timer);
            // }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    // 根据模块获取商品分类
    moduleSelect(module, materials) {
      goodSort(sessionStorage.getItem("token"), module, materials)
        .then((res) => {
          if (res.data.status) {
            if (materials == "辅材采购") {
              this.classOptions = res.data.data[0].children;
            } else {
              this.classOptions = res.data.data;
            }
            console.log("pp", this.classOptions);
            // console.log("fenlei", this.classOptions);
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch((err) => {
          this.$message.error(err.message);
        });
    },
    classChange() {
      let goods_type_id = "";
      this.formLabelAlign.goods = "";
      if (this.formLabelAlign.module == 1) {
        goods_type_id = "";
        let customizedWaterList = this.classOptions.filter(function (item) {
          return item.id == 80;
        });
        console.log(customizedWaterList);
        if (customizedWaterList.length > 0) {
          customizedWaterList[0].child.forEach((item) => {
            if (item.id == this.formLabelAlign.class) {
              goods_type_id = 5;
            }
          });
        }
      } else if (this.formLabelAlign.module == 3) {
        goods_type_id = 6;
      }
      if (this.formLabelAlign.module == 6) {
        this.materials = "辅材采购";
      } else {
        this.materials = "";
      }
      this.getShopList(
        goods_type_id,
        this.formLabelAlign.class,
        this.materials
      );
    },
    goodsChange() {
      this.goodsOptions.forEach((item) => {
        if (item.id == this.formLabelAlign.goods) {
          this.formLabelAlign.brand_name = item.brand_name;
          if (this.formLabelAlign.module == 6) {
            let img = item.img.split(",")[0];
            this.imageUrl = this.imgHeader + img;
          } else {
            this.imageUrl = this.imgHeader + item.images;
          }
        }
      });
    },
    //关闭弹框
    handleClose(done) {
      done();
      this.clearData();
      this.$refs.managementForm.resetFields();
    },
    //获取列表数据
    searchUser() {
      this.loading = true;
      getPlatformPromotionList(
        this.token,
        this.formInline.goods_name,
        this.formInline.status,
        this.formInline.time,
        this.page,
        this.limit
      )
        .then((res) => {
          if (res.data.status == true) {
            this.tableData = res.data.data.data;
            this.total = res.data.data.total;
            this.tableData.forEach((item) => {
              if (item.img) {
                item.image = item.img;
                item.img = this.imgHeader + item.img;
                console.log(item.img);
              }
            });
            let timer = setTimeout(() => {
              this.loading = false;
              clearTimeout(timer);
            }, 400);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.msg);
        });
    },
    search() {
      this.page = 1;
      if (this.formInline.time == null) {
        this.formInline.time = "";
      }
      this.searchUser();
    },
    reset() {
      (this.formInline.goods_name = ""),
        (this.formInline.time = ""),
        (this.formInline.status = "");
      this.page = 1;
      this.searchUser();
    },
    //分页器
    //每页多少条
    handleSizeChange(val) {
      this.limit = val;
      this.searchUser();
    },
    //第几页
    handleCurrentChange(val) {
      this.page = val;
      this.searchUser();
    },

    // 序号排序
    indexMethod(index) {
      if (this.total < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },

    //状态值
    conditionUser(id, status) {
      endPlatformPromotionList(this.token, id, status)
        .then((res) => {
          if (res.data.status) {
            // this.searchUser();
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
              this.loading = false;
            }
            let timer = setTimeout(() => {
              this.$message.error(res.data.msg);
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    //启用
    handleEdit(index, row) {
      if (row.status === 1) {
        let is_status = 2;
        this.conditionUser(row.id, is_status);
      }
      this.searchUser();
    },
    //删除
    deleteUser(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delPlatformPromotionList(this.token, row.id).then((res) => {
            if (res.data.status) {
              this.$message({
                type: "success",
                message: "删除成功",
              });
              this.search();
            } else {
              this.$message.error(res.data.msg);
            }
          });
          // if (row.is_status == 2) {
          //   delPlatformPromotionList(this.token, row.id).then((res) => {
          //     if (res.data.status) {
          //       this.$message({
          //         type: "success",
          //         message: "删除成功",
          //       });
          //       this.search();
          //     } else {
          //       this.$message.error(res.data.msg);
          //     }
          //   });
          // } else {
          //   this.$message({
          //     type: "warning",
          //     message: "员工在职,无法删除",
          //   });
          // }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 新增
    handleAdd() {
      this.dialogVisible = true;
      this.disabled = false;
      this.clearData();
    },
    //编辑
    compile(index, row) {
      let obj = JSON.parse(JSON.stringify(row));
      this.formLabelAlign.id = obj.id;
      this.getDetail(obj.id, obj.goods_type);
      this.disabled = true;
      this.dialogVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.managementForm.resetFields();
      // });
    },
    //获取详情
    async getDetail(rowId, goods_type) {
      // this.loading = true;
      let res = await getPlatformPromotionDetail(this.token, rowId, goods_type)
        .then((res) => {
          if (res.data.status) {
            this.detailData = res.data.data;
            if (this.detailData.module == 4) {
              this.formLabelAlign.module = 1;
              this.moduleSelect(1, "");
              this.materials = "";
              this.fenleiListProps.children = "child";
            } else if (this.detailData.module == 5) {
              this.formLabelAlign.module = 3;
              this.moduleSelect(3, "");
              this.materials = "";
              this.fenleiListProps.children = "child";
            } else {
              this.formLabelAlign.module = this.detailData.module;
              this.moduleSelect(6, "辅材采购");
              this.materials = "辅材采购";
              this.fenleiListProps.children = "children";
            }
            if (this.detailData.module == 6) {
              this.formLabelAlign.class = this.detailData.good.category_id;
              this.classChange();
              this.imageUrl =
                this.imgHeader + this.detailData.good.img.split(",")[0];
            } else {
              this.formLabelAlign.class = this.detailData.good.goods_cat_id;
              this.classChange();
              this.imageUrl = this.imgHeader + this.detailData.good.images;
            }
            this.formLabelAlign.goods = this.detailData.goods_id;
            this.formLabelAlign.brand_name = this.detailData.good.brand.name;
            console.log("name", this.formLabelAlign.brand_name);
            this.formLabelAlign.split_up_num = this.detailData.type;
            this.formLabelAlign.sort = this.detailData.sort;
            //时间回显处理 将data 返回的时间push进去
            let tmpArr = [];
            tmpArr.push(new Date(this.detailData.start_time));
            tmpArr.push(new Date(this.detailData.end_time));
            this.formLabelAlign.time = tmpArr;
            console.log("编辑", this.formLabelAlign.time);
          } else {
            if (res.data.msg == "token失效,请重新进行登录") {
              this.$router.push("/login");
            }
            if (res.data.msg == "此账号没有权限") {
              this.$message.error(res.data.msg);
            }
          }
        })
        .catch((err) => {
          console.log(err.message);
        });
    },
    // 判断日期时间类型是否是 2023-02-10 17:12:12
    isDataType(str) {
      // let mm = "Thu May 02 2024 01:01:01 GMT+0800 (GMT+08:00)";
      // let nn = "2024-05-03 02:30:23";
      // var dateTime = mm.match(
      //   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/
      // );
      // var dateTimes = nn.match(
      //   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/
      // );
      // console.log("dateTime", dateTime); //如果不是 2023-02-10 17:12:12这种类型返回null
      // console.log("dateTimes", dateTimes); //如果不是 2023-02-10 17:12:12这种类型返回null
      var dateTimess = str
        .toString()
        .match(
          /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/
        );
      // console.log("dateTimess", dateTimess); //如果不是 2023-02-10 17:12:12这种类型返回null
      return dateTimess;
    },
    // 将时日期式转变为2023-02-10 17:12:12格式
    convertDates(arr) {
      const result = [];
      const resultTime = [];
      const datePattern =
        /^([a-zA-Z]{3}\s+\d{1,2}\s+\d{4}\s+\d{2}:\d{2}:\d{2}\s+GMT[+-]\d{4}\s+\(GMT[+-]\d{4}\))?$/;
      arr.forEach((item) => {
        console.log("item", item);
        item = item.toString();
        // 解析并转换日期时间格式
        const [_, month, day, year, hour, minute, second, tz] = item.match(
          /(\w+)\s+(\d+)\s+(\d+)\s+(\d+:\d+:\d+)\s/
        );
        const months = [
          "Jan",
          "Feb",
          "Mar",
          "Apr",
          "May",
          "Jun",
          "Jul",
          "Aug",
          "Sep",
          "Oct",
          "Nov",
          "Dec",
        ];
        const monthIndex = months.indexOf(month);
        const formattedDate = `${year}-${
          monthIndex + 1 > 9 ? monthIndex + 1 : "0" + (monthIndex + 1)
        }-${day.padStart(2, "0")} ${hour}:${minute}:${second}`;
        result.push(formattedDate);
        // console.log("formattedDate", formattedDate);
      });
      result.map((timeStr) => {
        // 使用正则表达式移除':undefined'和最后一个':'及其后的所有字符
        timeStr = timeStr.replace(/:undefined:.+$/, "");
        // console.log("timeStr", timeStr);
        resultTime.push(timeStr);
        // 或者使用slice方法，假设时间格式固定长度，直接截取前14+6位
        // return timeStr.slice(0, 111);
      });
      return resultTime;
      // console.log("result", result);
      // console.log("resultTime", resultTime);
      // return result;
    },

    getNowTime(time) {
      let date = new Date(time);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let hour = date.getHours();
      let minute = date.getMinutes();
      let seconds = date.getSeconds();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      hour = hour < 10 ? "0" + hour : hour;
      minute = minute < 10 ? "0" + minute : minute;
      seconds = seconds < 10 ? "0" + seconds : seconds;
      return year + "-" + month + "-" + day;
    },
    datePicker2(e) {
      // console.log("e", e);
      // this.convertDates(e);
      // this.time1 = "";
      // if (e != null) {
      //   console.log(e);
      //   e.forEach((item) => {
      //     this.time1 += this.getNowTime(item) + ",";
      //   });
      //   this.time1 = this.time1.slice(0, this.time1.length - 1);
      // } else {
      //   this.time1 = "";
      // }
      // console.log("jjj", this.time1);
      // this.ruleForm.contract_period = this.time1;
    },
    //新增员工
    handleRemove() {},
    //添加员工
    // save() {
    //   employee(
    //     this.token,
    //     this.imageUrl1,
    //     this.formLabelAlign.region,
    //     this.formLabelAlign.name,
    //     this.formLabelAlign.user_id,
    //     this.authority_id
    //   ).then((res) => {
    //     if (res.data.status) {
    //       this.$message({
    //         message: "保存成功",
    //         type: "success",
    //       });
    //       this.clearData();
    //       this.searchUser();
    //     } else {
    //       if (res.data.msg == "token失效,请重新进行登录") {
    //         this.$router.push("/login");
    //         let timer = setTimeout(() => {
    //           this.$message.error("错误，请刷新");
    //         }, 5000);
    //       }
    //       this.$message.error(res.data.msg);
    //     }
    //   });
    // },

    //确定添加员工的回调
    submitData(managementForm) {
      this.$refs[managementForm].validate((valid) => {
        if (valid) {
          let module = "";
          if (this.formLabelAlign.module == 1) {
            module = 4;
          }
          if (this.formLabelAlign.module == 3) {
            module = 5;
          }
          if (this.formLabelAlign.module == 6) {
            module = 6;
          }
          console.log("id", this.formLabelAlign);
          if (this.isDataType(this.formLabelAlign.time[0]) == null) {
            this.formLabelAlign.time = this.convertDates(
              this.formLabelAlign.time
            );
          }
          if (this.formLabelAlign.id) {
            addPlatformPromotionList(
              this.token,
              this.formLabelAlign.id,
              this.formLabelAlign.goods,
              module,
              this.formLabelAlign.split_up_num,
              this.formLabelAlign.sort,
              this.formLabelAlign.time,
              1
            ).then((res) => {
              console.log(res);
              if (res.data.status) {
                this.$message({
                  message: res.data.msg,
                  type: "success",
                  onClose: (res) => {},
                });
                this.search();
                this.dialogVisible = false;
                this.clearData();
                this.$refs[managementForm].resetFields();
              } else {
                this.$message.error(res.data.msg);
              }
            });
          } else {
            addPlatformPromotionList(
              this.token,
              "",
              this.formLabelAlign.goods,
              module,
              this.formLabelAlign.split_up_num,
              this.formLabelAlign.sort,
              this.formLabelAlign.time,
              1
            ).then((res) => {
              console.log(res);
              if (res.data.status) {
                this.$message({
                  message: res.data.msg,
                  type: "success",

                  onClose: (res) => {},
                });
                this.search();
                this.dialogVisible = false;
                this.clearData();
                this.$refs[managementForm].resetFields();
              } else {
                this.$message.error(res.data.msg);
              }
            });
          }
        }
      });
    },

    //超出文件个数的回调
    handleExceed() {
      this.$message({
        type: "warning",
        message: "超出最大上传文件数量的限制！",
      });
      return;
    },
    //这是我自定义的移除事件
    handleClosedelete(i) {
      this.fileList.splice(i, 1); //删除上传的文件
    },
    //上传文件的格式
    beforeUpload(file) {
      if (file.type != "" || file.type != null || file.type != undefined) {
        //截取文件的后缀，判断文件类型
        const FileExt = file.name.replace(/.+\./, "").toLowerCase();
        //计算文件的大小
        const isLt5M = file.size / 1024 / 1024 < 1; //这里做文件大小限制
        //如果大于50M
        if (!isLt5M) {
          this.$message.error("上传文件大小不能超过 1MB!");
          return false;
        }
        //如果文件类型不在允许上传的范围内
        if (this.fileType.includes(FileExt)) {
          return true;
        } else {
          this.$message.error("上传文件格式不正确!");
          return false;
        }
      }
    },

    //上传文件的事件
    uploadFiles(item) {
      this.$message("文件上传中........");
      //上传文件的需要formdata类型;所以要转
      uploadFiles(item.file).then((res) => {
        if (res.data.status != false || res.data.id != null) {
          console.log(res);
          res.data.data.saveurl; //半截
          res.data.data.weburl; //全拼
          this.imageUrl1 = res.data.data.saveurl;
          this.imageUrl = res.data.data.weburl;
          this.fileList.push(item.file); //成功过后手动将文件添加到展示列表里
          let i = this.fileList.indexOf(item.file);
          this.handleSuccess();
        }
      });
    },
    //上传成功后的回调
    handleSuccess() {
      this.$message({
        message: "上传成功",
        type: "success",
      });
      this.handleClosedelete();
    },
    formatUserState(row) {
      let is_status = row.is_status;
      if (is_status === 1) {
        return "在职";
      } else if (is_status === 2) {
        return "离职";
      } else {
        return "未审核";
      }
    },
  },
  watch: {},
  mounted() {
    // this.toAdd();
    this.search();
  },
};
</script>

<style scoped>
.confirm {
  margin-left: 40%;
}

.movement {
  margin-right: 10px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.oneLine {
  display: flex;
  justify-content: space-between;
  /* margin-bottom: 14px; */
}
.el-radio-group {
  width: 200px;
}
</style>